﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace QL_Truong_Hoc
{
    public partial class frmChonLopNghe : DevExpress.XtraEditors.XtraForm
    {
        public bool Selected { get; set; }
        public int KhungDaoTaoID { get; set; }
        public int TrinhDoDaoTaoID { get; set; }
        public int KhoaID { get; set; }
        public int KhoasID { get; set; }
        public int NgheID { get; set; }
        public int LopID { get; set; }

        public string KhungDaoTaoTen { get; set; }
        public string TrinhDoDaoTaoTen { get; set; }
        public string KhoaTen { get; set; }
        public string KhoasTen { get; set; }
        public string NgheTen { get; set; }
        public string LopTen { get; set; }

        public frmChonLopNghe(int intTrinhDo = clsConst.gcintNoneValue)
        {
            InitializeComponent();
            this.TrinhDoDaoTaoID = clsConst.gcintNoneValue;
            if (intTrinhDo > clsConst.gcintNoneValue) this.TrinhDoDaoTaoID = intTrinhDo;
        }

        private void frmChonKhungDaoTao_Load(object sender, EventArgs e)
        {
            if (this.TrinhDoDaoTaoID > clsConst.gcintNoneValue) this.mLopSelectAllWithDetailBindingSource.Filter = string.Format("TD_ID = {0}", this.TrinhDoDaoTaoID);

            // TODO: This line of code loads data into the 'qLTHDataSet.mLopSelectAllWithDetail' table. You can move, or remove it, as needed.
            this.mLopSelectAllWithDetailTableAdapter.Fill(this.qLTHDataSet.mLopSelectAllWithDetail);
            // TODO: This line of code loads data into the 'qLTHDataSet.mNghe' table. You can move, or remove it, as needed.
            this.mNgheTableAdapter.Fill(this.qLTHDataSet.mNghe);
            // TODO: This line of code loads data into the 'qLTHDataSet.mKhoaHoc' table. You can move, or remove it, as needed.
            this.mKhoaHocTableAdapter.Fill(this.qLTHDataSet.mKhoaHoc);
            // TODO: This line of code loads data into the 'qLTHDataSet.mKhoa' table. You can move, or remove it, as needed.
            this.mKhoaTableAdapter.Fill(this.qLTHDataSet.mKhoa);
            // TODO: This line of code loads data into the 'qLTHDataSet.mTrinhDoDaoTao' table. You can move, or remove it, as needed.
            this.mTrinhDoDaoTaoTableAdapter.Fill(this.qLTHDataSet.mTrinhDoDaoTao);

            this.Selected = false;
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            try
            {
                //lấy dữ liệu
                this.LopID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colLop_ID));

                if (this.LopID <= 0)
                {
                    clsCommon.fncMsgInfo("Hãy chọn một lớp học.");
                    dgvKhung.Focus();
                    return;
                }

                this.KhungDaoTaoID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colKDT_ID));
                this.TrinhDoDaoTaoID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colTD_ID));
                this.KhoaID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colKH_ID));
                this.KhoasID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colKHS_ID));
                this.NgheID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colNG_ID));
                this.LopID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colLop_ID));

                this.KhungDaoTaoTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colKDT_ID));
                this.TrinhDoDaoTaoTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colTD_ID));
                this.KhoaTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colKH_ID));
                this.KhoasTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colKHS_ID));
                this.NgheTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colNG_ID));
                this.LopTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colLop_ten));

                this.Selected = true;

                this.Close();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {               
                this.Close();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }
    }
}